package com.ldzy.webase.controller;

import com.auth0.jwt.JWT;
import com.ldzy.webase.annotation.PassToken;
import com.ldzy.webase.annotation.UserLoginToken;
import com.ldzy.webase.entity.Slideshow;
import com.ldzy.webase.entity.User;
import com.ldzy.webase.exception.ExceptionResponse;
import com.ldzy.webase.exception.ExceptionResponseCode;
import com.ldzy.webase.service.SlideshowService;
import com.ldzy.webase.utils.Response;
import com.ldzy.webase.utils.ResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author ：Lq
 * @version ：1.0
 * @date ：2022/10/25 21:58
 * @description ：t_slideshow-轮播图表-控制层
 */
@RestController
@ResponseBody
@RequestMapping("/slideshow")
public class SlideshowController {
    @Autowired
    private SlideshowService slideshowService;

    /**
     * @author ：Lq
     * @date ：2022/10/26 13:52
     * @description ：获取并返回所有轮播图列表
     */
    @GetMapping("/list")
    @PassToken
    public Response getSlideshowAllByType(String type) {
        // 判断type参数是否为空
        if (type == null && type.equals("")) {
            throw ExceptionResponse.build(ExceptionResponseCode.ERROR_NOT_TOKEN);// (401, "服务器开小差了")
        }

        // 获取轮播图
        List<Slideshow> slideshowAllByType = slideshowService.getSlideshowAllByType(type);

        // 将 数据 返回给前端
        return Response.build(ResponseCode.SUCCESS, slideshowAllByType);
    }
}
